package com.dean.sql.service.impl;

import com.dean.sql.service.DeanSql;

import java.util.Locale;

/**
 * @ClassName DeanMysql
 * @Description
 * @Date 2022/1/1 13:57
 * @Created by dean
 */
public class DeanOracle implements DeanSql {
    @Override
    public String getTableInfoSql() {
        return "select COMMENTS TABLE_COMMENT,TABLE_NAME from user_tab_comments where table_name = ? and table_type='TABLE'";

    }

    @Override
    public String getFieldInfoSql() {
        return
        "SELECT A.COLUMN_NAME,A.COMMENTS COLUMN_COMMENT,B.DATA_TYPE,NVL(B.DATA_PRECISION,B.DATA_LENGTH) DATA_LENGTH,B.DATA_SCALE,CASE WHEN C.COLUMN_NAME IS NOT NULL THEN 'Y' ELSE 'N' END  PK_FLAG\n" +
                "FROM USER_COL_COMMENTS A \n" +
                "LEFT JOIN USER_TAB_COLS B ON  A.TABLE_NAME = B.TABLE_NAME AND A.COLUMN_NAME=B.COLUMN_NAME \n" +
                "LEFT JOIN USER_CONS_COLUMNS C ON  A.TABLE_NAME = C.TABLE_NAME AND A.COLUMN_NAME = C.COLUMN_NAME AND C.position IS NOT NULL\n" +
                "WHERE A.TABLE_NAME = ? \n" +
                "ORDER BY COLUMN_ID;";
       // return "SELECT A.COLUMN_NAME,A.COMMENTS COLUMN_COMMENT,B.DATA_TYPE,NVL(B.DATA_PRECISION,B.DATA_LENGTH) DATA_LENGTH,B.DATA_SCALE FROM USER_COL_COMMENTS A, USER_TAB_COLS B where A.TABLE_NAME = B.TABLE_NAME AND A.COLUMN_NAME=B.COLUMN_NAME AND  A.TABLE_NAME = ? ORDER BY COLUMN_ID";
    }

    @Override
    public String getPageSql(String sql) {
        String exeSql = "select * from ("+sql+") t where rownum<= ?";
        return exeSql;
    }

    @Override
    public String covertTableName(String tableName) {
        return tableName.toUpperCase();
    }
}
